package com.github.grpc.client.service;

import io.grpc.Attributes;
import io.grpc.NameResolver;
import io.grpc.NameResolverProvider;
import io.grpc.internal.GrpcUtil;
import mousio.etcd4j.EtcdClient;

import javax.annotation.Nullable;
import java.net.URI;

public class EtcdClientChannelResolverFactory extends NameResolverProvider {

    private final EtcdClient etcdClient;

    public EtcdClientChannelResolverFactory(EtcdClient etcdClient) {
        this.etcdClient = etcdClient;
    }

    @Nullable
    @Override
    public NameResolver newNameResolver(URI targetUri, Attributes params) {
        return new EtcdClientChannelNameResolver(targetUri.toString(), etcdClient, params, GrpcUtil.SHARED_CHANNEL_EXECUTOR);
    }

    @Override
    public String getDefaultScheme() {
        return "etcdClient";
    }

    @Override
    protected boolean isAvailable() {
        return true;
    }

    @Override
    protected int priority() {
        return 5;
    }
}
